<template>
	<view>
		<view style="display: flex;flex-direction: column;">
			<uni-card>
				<view style="display: flex;flex-direction: column;" @click="perfect">
					<text>姓名:{{message.name}}</text>
					<text>电话:{{message.phone}}</text>
					<text>地址:{{message.address}}</text>
					<text>金额:{{message.money}}</text>
					<text>{{message.type}}</text>
					<text>{{message.time}}</text>
				</view>
			</uni-card>
			<view style="display: flex; margin-top: 10px;" v-for="(item,index) in cake" :key="index">
				<image :src="item.cake.cakeImage" mode="aspectFit" style="width: 300rpx; height: 300rpx;" ></image>
				<view style="display: flex;flex-direction: column; font-size: 18px; color: #800;">
					<text>{{item.cake.cakeName}}</text>
					<uni-rate :max="5" v-model="item.cake.type"></uni-rate>
						<text>单价:${{item.cake.cakeMoney}}</text>
						<text>购买数:{{item.order.number}}</text>
						<text>总价:${{item.money}}</text>
				</view>
			</view>
		</view>
		<view style="bottom: 10rpx; width: 100%; position: absolute;">
			<uni-section type="line">
				<uni-goods-nav :buttonGroup="buttonGroup" :options="options" :fill="true" @buttonClick="buttonClick" />
			</uni-section>
		
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				message:{},
				cake:{},
				options: [{
					icon: 'map',
					text: '金额',
					info: 0
				}],
				buttonGroup: [
					{
						text: '取消订单',
						backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
						color: '#fff'
					},
					{
					text: '立即支付',
					backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
					color: '#fff'
				}],
				id:null,
			}
		},
		methods: {
			pay(){
				uni.request({
					url: this.api.pay,
					method: 'POST',
					data: {
						id:this.message.id
					},
					success: res => {
						uni.showToast({
							title:res.data.message,
							icon:"error",
							
						})
						this.getmessage(this.id)
					},
					fail: () => {},
					complete: () => {}
				});
			},
			buttonClick(e){
				console.log(e);
					
				if(e.index==1){
					this.pay()
				}
				else{
					uni.request({
						url: this.api.deletepay,
						method: 'POST',
						data: {
							id :this.message.id
						},
						success: res => {
							if(res.data.code==200){
								uni.navigateBack({
									delta:1
								})
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}
				// this.pay()
			},
			getcake(id){
				uni.request({
					url: this.api.AllOrder,
					method: 'POST',
					data: {
						id:id
					},
					success: res => {
						if(res.data.code==200){
							this.cake=res.data.obj
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			perfect(){
				uni.navigateTo({
					url: '/pages/perfect/perfect?OrderId='+this.message.orderId,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			getmessage(id){
				uni.request({
					url: this.api.findPayById,
					method: 'POST',
					data: {
						id:id
					},
					success: res => {
						if(res.data.code==200){
							this.message=res.data.obj
							this.options[0].info=this.message.money
							if(this.message.type=="已支付"){
								this.buttonGroup[0].text="已支付"
							}
							this.getcake(id)
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad(open) {
			uni.setNavigationBarTitle({
				title:open.orderId
			})
			this.id=open.id
			this.getmessage(open.id)
		}
	}
</script>

<style>

</style>
